package com.vvlive.caibao.smartcity.utils;


public class StringUtil {
	
	/**
	 * 得到发布者的名字
	 * [objectId,name]
	 * @param publisher
	 * @return
	 */
	public static String getPublisherName(String publisher) {
		int pos1 = publisher.indexOf(":");
		int pos2 = publisher.indexOf("]");
		return canSubstr(publisher) ? getPublisherPart(publisher, pos1 + 1, pos2) : publisher;
	}
	
	/**
	 * 得到发布者的objectId
	 * @param publisher
	 * @return
	 */
	public static String getPublisherObjectId(String publisher){
		int pos1 = publisher.indexOf("[");
		int pos2 = publisher.indexOf(":");
		return canSubstr(publisher) ? getPublisherPart(publisher, pos1 + 1, pos2) : publisher;
	}
//
//	public String getCurrentUserIdWithName(){
//		return "[" + Const.userInfo.getUserId() + ":" + Const.userInfo.getName() + "]";
//	}
	
	private static boolean canSubstr(String str){
		return str.indexOf(":") == -1;
	}
	
	/**
	 * 过滤数据
	 * @param src
	 * @return
	 */
	public static String filter(String src){
		return src.lastIndexOf("<script") != -1 ? src.split("<script")[0] : src;
	}
	
	/**
	 * 
	 * @param publisher
	 * @param start
	 * @param end
	 * @return
	 */
	private static String getPublisherPart(String publisher, int start, int end){
		return publisher.substring(start, end);
	}
	
}
